<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author xuanyan <xuanyan@geek-zoo.com>
 *
 */

set_time_limit(0);

class Action
{
    function index()
    {
        $time = time();
        $api = new ApiSina();
        // 发送微博队列
        $data = _model('tweet_list')->getList("WHERE send_time <= $time AND sent_time = 0 LIMIT 20");
        foreach ($data as $key => $val) {
            if ($info = _model('account')->read(array('id'=>$val['account_id']))) {
                $api->update($info['oauth_token'], $info['oauth_token_secret'], $val['content'], $val['pic']);
                _model('tweet_list')->update(array('id'=>$val['id']), array('sent_time'=>$time));
            }
        }
        // 抓取用户数据
        $data = _model('account')->getList("WHERE check_time < ($time - 86400) LIMIT 20");
        foreach ($data as $key => $val) {
            $info = $api->getUserInfo($val['oauth_token'], $val['oauth_token_secret']);
            if (isset($info['error'])) {
                continue;
            }
            $param = array(
                'followers_count' => $info['followers_count'],
                'friends_count' => $info['friends_count'],
                'statuses_count' => $info['statuses_count'],
                'check_time' => $time,
                'account_id' => $val['id']
            );
            _model('account_info')->create($param);
            _model('account')->update(array('id'=>$val['id']), array('check_time'=>$time));
        }

    }
}

?>